 #! /usr/bin/env python
import pygame
import math  
LEFT = 1
  

running = 1
class Agente(pygame.sprite.Sprite):
    
    def __init__(self):
        pygame.sprite.Sprite.__init__ (self) 
        SIZE = 10
        size = (SIZE,SIZE)
        self.speed = [1,1]
        image = pygame.Surface(size)
        image = image.convert()
        image.fill( (255,0,0) )
        self.image = image
        self.rect = image.get_rect()
        self.rect.topleft = (50, 50)
        
    def update(self ):
        
        self.rect = self.rect.move(self.speed)
        

    
    
screen = pygame.display.set_mode((320, 200))



# Recupero la pantalla
screen = pygame.display.get_surface()
# Inicializo Sprite
            
# Guardo area de la pantalla
area = screen.get_rect()

background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0,0,200))
background_rect = background.get_rect()

# Dibujo el fondo
screen.blit(background, (0,0))
c =0 
x = pygame.sprite.Group(Agente())
print "top right %s"%(str(area.topright))
print "bottom right %s"%(str(area.bottomright))
while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running = 0
    elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3:
        #print "You pressed the left mouse button at (%d, %d)" % event.pos
        x.update()
        while event.type != pygame.MOUSEBUTTONUP:
            event = pygame.event.poll()
            
            if event.type == pygame.MOUSEMOTION:
                
                x.update()
                # Dibujo el fondo
                screen.blit(background, (0,0))
                x.draw(screen)
                pygame.display.flip()
                
    elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
        
        print "You released the left mouse button at (%d, %d)" % event.pos
 
    # Dibujo el fondo
    screen.blit(background, (0,0))
    x.update()
    x.draw(screen)
    pygame.display.flip()
    
    
    if c == 15:
        c=0
        vel_x = float(raw_input("Nueva velocidad en X: "))
        vel_y = float(raw_input("Nueva velocidad en Y: "))
        x.sprites()[0].speed=[vel_x, vel_y]
        rad = math.atan2(x.sprites()[0].speed[1], x.sprites()[0].speed[0] )
        #print "Orientacion en rad = %s" % (rad)
        grados = math.degrees(rad)
        if (grados < 0):
            grados += 360
        print "Orientacion en grados = %s" % (grados)
    c+=1
    
    